﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Controllers;
using Microsoft.Win32;
using Interfaces;

namespace Projekt3
{
    ///Nedenstående samt GUI er lavet af Anders Madsen
    /// <summary>
    /// Interaction logic for ProduktData.xaml
    /// </summary>
    public partial class ProduktData : Window
    {
        List<IProduct> productlist = new List<IProduct>();
        List<IProductDetail> productdetailList = new List<IProductDetail>();
        int index;

        public ProduktData(List<IProduct> sendproductlist, int sendindex, FacadeController controller)
        {
            //Vi bruger vores index til at finde det valgte objekt, hvorefter vi fylder de forskellige labels
            //ud med den valgte data.
            InitializeComponent();
            productlist = sendproductlist;
            index = sendindex;
            lbl_productnumber.Content = sendproductlist[index].ProductNumber;
            lbl_brandcode.Content = sendproductlist[index].BrandCode;
            lbl_availibillitylevel.Content = sendproductlist[index].AvailabilityLevel;
            lbl_category.Content = sendproductlist[index].Category;
            lbl_productstatus.Content = sendproductlist[index].ProductStatus;
            lbl_price.Content = sendproductlist[index].Price;
            lbl_launchdate.Content = sendproductlist[index].LaunchDate.ToString();

            //Database kald der returnerer productdetail der passer til productnumber
            productdetailList = controller.ReturnerProductdetailFromProduct(int.Parse(sendproductlist[index].ProductNumber));
            foreach (IProductDetail productdetail in productdetailList)
            {
                lb_details.Items.Add(productdetail.Description);
            }
        }

        //Logik der opdaterer productdetail labelsne når der vælges en ny beskrivelse.
        private void lb_details_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            int index = lb_details.SelectedIndex;
            lbl_language.Content = productdetailList[index].Language;
            lbl_description.Content = productdetailList[index].Description;
            lbl_replacementnotes.Content = productdetailList[index].ReplacementsNotes;
        }

        //Når der bliver trykket på luk knappen
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }
    }
}
